//
//  OthersProfileViewController.m
//  League
//
//  Created by 崔璨 on 2018/1/25.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "OthersProfileViewController.h"
#import "JKBannarView.h"
#import "UILabel+extension.h"
#import "MyProfileViewController.h"

#define kBannerTopSpace 10
#define kBannerHeight kScreenWidth-20
#define kUserNameLabeHeight 50
#define kUserInfoLabeHeight 30
#define kCellBtnHeight 60
#define kCellTitleLabHeight 35

#define kFontSize 15
#define kTitleFontSize 13

#define kText @"could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available"
@interface OthersProfileViewController ()<UITableViewDelegate , UITableViewDataSource>
{
    NSBundle *bundle;
}
@property(strong , nonatomic) UITableView *tableV;

@end

@implementation OthersProfileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Profile";
    if (@available(iOS 11.0, *)) {
        self.tableV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    //    [self.view addSubview:self.tableV];//加载tableview
    [InternationalControl initUserLanguage];//初始化应用语言
    
    bundle = [InternationalControl bundle];
    [self TableView];
    // Do any additional setup after loading the view.
}
-(void)TableView
{
    
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 64)];//指定位置大小
    self.tableV.backgroundColor = [UIColor clearColor];
    [self.tableV setDelegate:self];//指定委托
    [self.tableV setDataSource:self];//指定数据委托
    self.tableV.estimatedRowHeight = 0;
    self.tableV.estimatedSectionHeaderHeight = 0;
    self.tableV.estimatedSectionFooterHeight = 0;
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableV];//加载tableview
    
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return  1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
    //    if (!cell) {
    //        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableViewCell"];
    //
    //    }
    static NSString *CellIdentifier = @"TableViewCell";
    // 通过indexPath创建cell实例 每一个cell都是单独的
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 10;
        cell.width = tableView.width;
    }
    NSMutableArray *imageViews = [[NSMutableArray alloc]init];
    [imageViews addObjectsFromArray:@[@"http://www.qqpk.cn/Article/UploadFiles/201208/20120820094458481.jpg",@"http://www.qqpk.cn/Article/UploadFiles/201402/20140226141151698.jpg",@"http://img1.touxiang.cn/uploads/allimg/111229/1206032193-33.jpg"]];
    JKBannarView *bannerView = [[JKBannarView alloc]initWithFrame:CGRectMake(0, 0, kBannerHeight, kBannerHeight) viewSize:CGSizeMake(kBannerHeight,kBannerHeight)];
    bannerView.tag = 100;
    bannerView.center = CGPointMake(cell.width/2, kBannerTopSpace+bannerView.height/2);
    bannerView.items = imageViews;
    [cell addSubview:bannerView];
    
    [bannerView imageViewClick:^(JKBannarView * _Nonnull barnerview, NSInteger index) {
        if (barnerview.tag == 100) {
            [self lookBigImage:imageViews];
        }
        NSLog(@"点击图片%ld",index);
    }];
    
    
    UILabel *userNameLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/2, kUserNameLabeHeight)];
    userNameLab.center = CGPointMake(cell.width/2, bannerView.y+bannerView.height+userNameLab.height / 2);
    //    userNameLab.backgroundColor = [UIColor redColor];
    userNameLab.textAlignment = NSTextAlignmentCenter;
    userNameLab.adjustsFontSizeToFitWidth = YES;
    [cell addSubview:userNameLab];
    userNameLab.text = @"CATransaction";
    userNameLab.font=[UIFont fontWithName:kFontName size:userNameLab.height*0.8];
    
    UILabel *UserInfolab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/2, kUserInfoLabeHeight)];
    UserInfolab.center = CGPointMake(cell.width/2, userNameLab.y+userNameLab.height+UserInfolab.height / 2);
    //    UserInfolab.backgroundColor = [UIColor yellowColor];
    UserInfolab.textAlignment = NSTextAlignmentCenter;
    UserInfolab.adjustsFontSizeToFitWidth = YES;
    [cell addSubview:UserInfolab];
    UserInfolab.text = @"MobileCoreServices.framework";
    UserInfolab.font=[UIFont fontWithName:kFontName size:UserInfolab.height*0.5];
    
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kCellBtnHeight, kCellBtnHeight)];
    leftBtn.center = CGPointMake(5+leftBtn.width/2, bannerView.y+bannerView.height+leftBtn.height/2+kBannerTopSpace);
    //    leftBtn.backgroundColor = [UIColor redColor];
    [leftBtn setImage:[UIImage imageNamed:@"cellCancel"] forState:UIControlStateNormal];
    [cell addSubview:leftBtn];
    
    float titleLabW = cell.width/5-5;
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kCellBtnHeight, kCellBtnHeight)];
    rightBtn.center = CGPointMake(cell.width-rightBtn.width/2-5, bannerView.y+bannerView.height+rightBtn.height/2+kBannerTopSpace);
    //    rightBtn.backgroundColor = [UIColor greenColor];
    [rightBtn setImage:[UIImage imageNamed:@"cellshouchang"] forState:UIControlStateNormal];
    [cell addSubview:rightBtn];
    
    
    UILabel *aboutMeTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, UserInfolab.y+UserInfolab.height+kBannerTopSpace, titleLabW, kCellTitleLabHeight)];
    //    aboutMeTitleLab.backgroundColor = [UIColor redColor];
    //    aboutMeTitleLab.font = [UIFont systemFontOfSize:kFontSize];
    aboutMeTitleLab.text = [bundle localizedStringForKey:@"AboutMe" value:nil table:@"hello"];
    aboutMeTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    aboutMeTitleLab.textColor = titleFontColor;
    aboutMeTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:aboutMeTitleLab];
    
    float aboutMelabHeight =[self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *aboutMeInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeTitleLab.x+aboutMeTitleLab.width+10, UserInfolab.y+UserInfolab.height+kBannerTopSpace, cell.width-aboutMeTitleLab.width-15, aboutMelabHeight)];
    aboutMeInfoLab.numberOfLines = 0;
    aboutMeInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    //    aboutMeInfoLab.font = [UIFont systemFontOfSize:kFontSize];
    aboutMeInfoLab.text = kText;
    [cell addSubview:aboutMeInfoLab];
    
    
    UILabel *EducationTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, aboutMeInfoLab.y+aboutMeInfoLab.height, titleLabW, kCellTitleLabHeight)];
    //    EducationTitleLab.backgroundColor = [UIColor redColor];
    EducationTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    EducationTitleLab.text = [bundle localizedStringForKey:@"Education" value:nil table:@"hello"];
    EducationTitleLab.textColor = titleFontColor;
    EducationTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:EducationTitleLab];
    
    float educationlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *educationInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, aboutMeInfoLab.y+aboutMeInfoLab.height, aboutMeInfoLab.width, educationlabHeight)];
    educationInfoLab.numberOfLines = 0;
    educationInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    educationInfoLab.text = kText;
    [cell addSubview:educationInfoLab];
    
    
    UILabel *professionTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, educationInfoLab.y+educationInfoLab.height, titleLabW, kCellTitleLabHeight)];
    //    professionTitleLab.backgroundColor = [UIColor redColor];
    professionTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    professionTitleLab.text = [bundle localizedStringForKey:@"Profession" value:nil table:@"hello"];
    professionTitleLab.textColor = titleFontColor;
    professionTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:professionTitleLab];
    
    float professionlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *professionInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, educationInfoLab.y+educationInfoLab.height, aboutMeInfoLab.width, professionlabHeight)];
    professionInfoLab.numberOfLines = 0;
    professionInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    professionInfoLab.text = kText;
    [cell addSubview:professionInfoLab];
    
    
    UILabel *interestsTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, professionInfoLab.y+professionInfoLab.height, titleLabW, kCellTitleLabHeight)];
    //    interestsTitleLab.backgroundColor = [UIColor redColor];
    interestsTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    interestsTitleLab.text = [bundle localizedStringForKey:@"Interests" value:nil table:@"hello"];
    interestsTitleLab.textColor = titleFontColor;
    interestsTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:interestsTitleLab];
    
    float interestslabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *interestsInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, professionInfoLab.y+professionInfoLab.height, aboutMeInfoLab.width, interestslabHeight)];
    interestsInfoLab.numberOfLines = 0;
    interestsInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    interestsInfoLab.text = kText;
    //    interestsInfoLab.textColor = titleFontColor;
    
    [cell addSubview:interestsInfoLab];
    
    
    UILabel *interestedTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, interestsInfoLab.y+interestsInfoLab.height, titleLabW, kCellTitleLabHeight)];
    //    interestedTitleLab.backgroundColor = [UIColor redColor];
    interestedTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    interestedTitleLab.text = [bundle localizedStringForKey:@"Interested" value:nil table:@"hello"];
    interestedTitleLab.textColor = titleFontColor;
    interestedTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:interestedTitleLab];
    
    float interestedlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *interestedInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, interestsInfoLab.y+interestsInfoLab.height, aboutMeInfoLab.width, interestedlabHeight)];
    interestedInfoLab.numberOfLines = 0;
    interestedInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    interestedInfoLab.text = kText;
    [cell addSubview:interestedInfoLab];
    
    
    UILabel *GroupsTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, interestedInfoLab.y+interestedInfoLab.height, titleLabW, kCellTitleLabHeight)];
    //    GroupsTitleLab.backgroundColor = [UIColor redColor];
    GroupsTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    GroupsTitleLab.text = [bundle localizedStringForKey:@"Groups" value:nil table:@"hello"];
    GroupsTitleLab.textColor = titleFontColor;
    GroupsTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:GroupsTitleLab];
    
    float GroupslabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *GroupsInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, interestedInfoLab.y+interestedInfoLab.height, aboutMeInfoLab.width, GroupslabHeight)];
    GroupsInfoLab.numberOfLines = 0;
    GroupsInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    GroupsInfoLab.text = kText;
    [cell addSubview:GroupsInfoLab];
    
    
    UILabel *religionTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, GroupsInfoLab.y+GroupsInfoLab.height, titleLabW, kCellTitleLabHeight)];
    //    religionTitleLab.backgroundColor = [UIColor redColor];
    religionTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
    religionTitleLab.text = [bundle localizedStringForKey:@"Religion" value:nil table:@"hello"];
    religionTitleLab.textColor = titleFontColor;
    religionTitleLab.textAlignment = NSTextAlignmentRight;
    [cell addSubview:religionTitleLab];
    
    float religionlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    UILabel *religionInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, GroupsInfoLab.y+GroupsInfoLab.height, aboutMeInfoLab.width, religionlabHeight)];
    religionInfoLab.numberOfLines = 0;
    religionInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
    religionInfoLab.text = kText;
    [cell addSubview:religionInfoLab];
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"row:%@ - section:%@",@(indexPath.row) , @(indexPath.section));
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    float aboutMelabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    float educationlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    float professionlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    float interestslabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    float interestedlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    float groupslabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    float religionlabHeight = [self calculateRowHeight:kText fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:kText fontSize:kFontSize]:kCellTitleLabHeight;
    
    return kBannerHeight + kBannerTopSpace+kBannerTopSpace+kUserNameLabeHeight+kUserInfoLabeHeight+aboutMelabHeight+educationlabHeight+professionlabHeight+interestslabHeight+interestedlabHeight+groupslabHeight+religionlabHeight;
}
- (CGFloat)calculateRowHeight:(NSString *)string fontSize:(NSInteger)fontSize{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};//指定字号
    CGRect rect = [string boundingRectWithSize:CGSizeMake(self.view.width/1.8, 0)/*计算高度要先指定宽度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    return rect.size.height;
}
-(void)toEdit:(UIButton *)btn
{
    MyProfileViewController *myProFileVc = [[MyProfileViewController alloc] init];
    myProFileVc.isRegister = NO;
    [self.navigationController pushViewController:myProFileVc animated:YES];
}
-(void)lookBigImage:(NSMutableArray *)imageArr
{
    
    UIView *bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
    bgview.backgroundColor = [UIColor blackColor];
    [[UIApplication sharedApplication].keyWindow addSubview:bgview];
    JKBannarView *bannerView = [[JKBannarView alloc]initWithFrame:CGRectMake(0, 0, kBannerHeight, kBannerHeight) viewSize:CGSizeMake(kBannerHeight,kBannerHeight)];
    bannerView.tag = 111;
    bannerView.center = CGPointMake(bgview.width/2, bgview.height/2);
    bannerView.items = imageArr;
    [bgview addSubview:bannerView];
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
    //设置点击次数和点击手指数
    tapGesture.numberOfTapsRequired = 1; //点击次数
    tapGesture.numberOfTouchesRequired = 1; //点击手指数
    [bgview addGestureRecognizer:tapGesture];
    
}
-(void)tapGesture:(UITapGestureRecognizer *)sender
{
    [sender.view removeFromSuperview];
    //轻击后要做的事情
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
